package com.njym.java.security.app.rest;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.njym.java.security.app.biz.TravelHeroBiz;
import com.njym.java.security.app.entity.TravelHero;
import com.njym.java.security.common.msg.TableResultResponse;
import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("travelHero")
public class TravelHeroController extends BaseController<TravelHeroBiz,TravelHero> {


    /**
     * 获取365英雄人物列表
     * @return
     */
    @RequestMapping(value = "/getLists", method = RequestMethod.GET)
    @ResponseBody
    public Object getLists(@RequestParam(defaultValue = "10") int limit,
        @RequestParam(defaultValue = "1") int page){
        Example example = new Example(TravelHero.class);
        example.createCriteria().andEqualTo("deleted", 0).andNotEqualTo("id", 2).andNotEqualTo("id", 3);
        example.setOrderByClause("id DESC");
        PageHelper.startPage(page, limit);
        List<TravelHero> list = baseBiz.selectByExample(example);
        long total = PageInfo.of(list).getTotal();
        int totalPages =  (int) Math.ceil((double) total / limit);
        Map<String, Object> data = new HashMap<>(3);
        data.put("list", list);
        data.put("total", total);
        data.put("totalPages", totalPages);
        return ResponseUtil.ok(data);
    }

}